<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:pm="http://primefaces.org/mobile">

<f:view renderKitId="PRIMEFACES_MOBILE" />

<h:head>

	<script type="text/javascript">            
				function iniciovotar(data) {
					PrimeFaces.navigate('#votar',{});
                }

				function wait(data) {
					PrimeFaces.navigate('#resultado',{});
                }

				function resultado(data) {
					gresultado.renderMessage({summary:'Resultado Votacion', detail: data, severity: 0});
                }
				
            </script>
</h:head>

<h:body>


	

		<pm:page id="main" swatch="b">
			<pm:header title="Login" swatch="b" />
			<pm:content>

				<h:form id="login">
					<p:growl id="growl" widgetVar="growl" />

					<p:inputText required="true" value="#{loginBean.username}" />

					<p:separator />

					<p:commandButton update="login" value="Ingresar" icon="refresh"
						actionListener="#{loginBean.loginmobile}"
						disabled="#{loginBean.inLogin}" />

					<p:socket onMessage="iniciovotar" channel="/#{loginBean.username}" />

					<p:socket onMessage="wait" channel="/wait#{loginBean.username}" />


				</h:form>


			</pm:content>

		</pm:page>

		<!-- Votar -->
		<pm:page id="votar" swatch="b">
			<pm:header title="Votar" swatch="b">
				<f:facet name="left">
					<p:button value="Volver" icon="back" onclick="PrimeFaces.back()" />
				</f:facet>
			</pm:header>

			<pm:content>
				<h:form>
					<h3>Votacion</h3>
					
						<p:commandButton value="Afirmativo" icon="check"
							actionListener="#{loginBean.votar(true)}" />
						<p:commandButton value="Negativo" icon="delete"
							actionListener="#{loginBean.votar(false)}" />
					

				</h:form>
			</pm:content>
		</pm:page>

		<!-- Resultado -->
		<pm:page id="resultado" swatch="b">
			<pm:header title="Resultado" swatch="b">
				<f:facet name="left">
					<p:button value="Volver" icon="back" onclick="PrimeFaces.back()" />
				</f:facet>
			</pm:header>

			<pm:content>
				<h:form id="rest">
					<h3>Resultado</h3>

					<p:outputLabel value="Cant. Votos SI: #{asistenciaBean.countSi}"
						id="outSi" />
					<p:outputLabel value="Cant. Votos NO: #{asistenciaBean.countNo}"
						id="outNo" />

					<p:socket onMessage="resultado" channel="/resultado">
						<p:ajax update=":rest:outSi,:rest:outNo" />
					</p:socket>

					<p:growl widgetVar="gresultado" />

				</h:form>
			</pm:content>
		</pm:page>
	

</h:body>
</html>

